from django.db import models
import datetime 

# Models
class Lecture(models.Model):
    class Admin:
        pass

    # Attributes
    videoURL = models.CharField("Video URL", max_length=1028)
    audioURL = models.CharField("Audio URL", max_length=1028)
    lectureTopic = models.CharField("Lecture Topic", max_length=512)
    lectureDescription = models.CharField("Lecture Description", max_length=512)

    # __str__ (toString)
    def __str__(self): 
        return self.lectureTopic

class Teacher(models.Model):
    class Admin:
        pass
    
    # Attributes
    titleEN = models.CharField("Title EN", max_length=50)
    titleZH = models.CharField("Title ZH", max_length=50)
    fullNameEN = models.CharField("Fullname EN", max_length=128)
    fullNameZH = models.CharField("Fullname ZH", max_length=128)
    departmentEN = models.CharField("Department EN", max_length=128)
    departmentZH = models.CharField("Department ZH", max_length=128)
    publishDate = models.DateTimeField("Modify Date", default=datetime.datetime.now)
    email = models.CharField("Email", max_length=128)

    # __str__ (toString)
    def __str__(self): 
        return self.titleEN + " " + self.fullNameEN

class Course(models.Model):
    class Admin:
        pass
    
    # Attributes
    #teacher = models.ForeignKey(Teacher, edit_inline=models.STACKED, num_in_admin=1)
    teachers = models.ManyToManyField(Teacher)
    lecture = models.ManyToManyField(Lecture)

    lectureType = models.CharField("Lecture Type", max_length=2)
    nameEN = models.CharField("Lecture Name EN", max_length=128)
    nameZH = models.CharField("Lecture Name ZH", max_length=128)
    semester = models.CharField("Semester", max_length=10)
    courseId = models.CharField("Course Id", max_length=10)
    #courseDescription = models.CharField("Course Description", max_length=20480)
    courseDescription = models.TextField("Course Description", max_length=20480, blank=True)

    courseAbstract = models.CharField("Course Abstract", max_length=2048)
    syllabus = models.CharField("Syllabus", max_length=20480)
    schedule = models.CharField("Schedule", max_length=20480)
    resources = models.CharField("Resources", max_length=20480)
    lectureMaterial = models.CharField("Lecture Material", max_length=20480)
    assignments = models.CharField("Assignments", max_length=20480)
    ceibaSite = models.CharField("CEIBA Site", max_length=2048)  # I remember we had problems with URLField in another project (TODO: verify)
    additionalWebSites = models.TextField("Additional Web Sites", null=True, max_length=2048)  # I remember we had problems with URLField in another project (TODO: verify)
    publishDate = models.DateTimeField("Modify Date", default=datetime.datetime.now)
    
    class Meta: 
        # Order by english name
        ordering = ['nameEN']
    
    # __str__ (toString)
    def __str__(self): 
        return self.nameEN
        
    def get_absolute_url(self):
        return "/viewCourse/%i/" % self.id
        
 
# One College consists of several departments
class College(models.Model):
    class Admin:
        pass
    
    # Attributes
    nameEN = models.CharField("Name EN", max_length=128)
    nameZH = models.CharField("Name ZH", max_length=128)
    
    # __str__ (toString)
    def __str__(self): 
        return self.nameEN


# One Department is part of a College
class Department(models.Model):
    class Admin:
        pass
    
    # Attributes
    nameEN = models.CharField("Name EN", max_length=128)
    nameZH = models.CharField("Name ZH", max_length=128)
    college = models.ManyToManyField(College)
    course = models.ManyToManyField(Course)
    
    # __str__ (toString)
    def __str__(self): 
        return self.nameEN

   
class DailyQuote(models.Model):
    class Admin:
        pass
    
    # Attributes
    quoteEN = models.CharField("Quote EN", max_length=1024)
    quoteCN = models.CharField("Quote ZH", max_length=1024)
    publishDate = models.DateTimeField("Modify Date", default=datetime.datetime.now)
    
    class Meta: 
        # Order by english name
        ordering = ['quoteEN']
    
    # __str__ (toString)
    def __str__(self): 
        return self.quoteEN
    

